home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / flick.pro < prev    next >
Text File  |  1997-07-08  |  3KB  |  129 lines

  1. ; $Id: flick.pro,v 1.3 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1988-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5. ;
  6.  
  7. pro flick,a,b,rate    ;Flicker between the two output frames at a given rate.
  8.             ; a and b = images scaled from 0 to 255.
  9.             ;To terminate, type any key except F or S.
  10.             ;Rate = frames per second.
  11.             ; Type F to flick faster by a factor of 2
  12.             ;  S to flick slower by a factor of 2.
  13. ;+
  14. ; NAME:
  15. ;    FLICK
  16. ;
  17. ; PURPOSE:
  18. ;    Flicker between two output images at a given rate.
  19. ;
  20. ; CATEGORY:
  21. ;    Image display, animation.
  22. ;
  23. ; CALLING SEQUENCE:
  24. ;    FLICK, A, B, Rate
  25. ;
  26. ; INPUTS:
  27. ;    A:    Byte image number 1, scaled from 0 to 255.
  28. ;    B:    Byte image number 2, scaled from 0 to 255.
  29. ;
  30. ; OPTIONAL INPUT PARAMETERS:
  31. ;    Rate:    The flicker rate.  The default is 1.0 sec/frame
  32. ;
  33. ; KEYWORD PARAMETERS:
  34. ;    None.
  35. ;
  36. ; OUTPUTS:
  37. ;    No explicit outputs.
  38. ;
  39. ; COMMON BLOCKS:
  40. ;    None.
  41. ;
  42. ; SIDE EFFECTS:
  43. ;    Sunview: Modifies the display, changes the write mask.
  44. ;    X and Windows: uses two additional pixmaps.
  45. ;
  46. ; RESTRICTIONS:
  47. ;    None.
  48. ;
  49. ; PROCEDURE:
  50. ;  SunView:
  51. ;    Image A is written to the bottom 4 bits of the display.
  52. ;    Image B is written to the top 4 bits.
  53. ;    Two color tables are created from the current table, one that
  54. ;    shows the low 4 bits using 16 of the original colors, and one
  55. ;    that shows the high 4 bits.  The color table is changed to
  56. ;    switch between images.
  57. ;  Other window systems:
  58. ;    two off screen pixmaps are used to contain the images.
  59. ;
  60. ; MODIFICATION HISTORY:
  61. ;    DMS, 3/ 88.
  62. ;    DMS, 4/92, Added X window and MS window optimizations.
  63. ;-
  64. common colors, r_orig, g_orig, b_orig, r_curr, g_curr, b_curr
  65. on_error,2                        ;Return to caller if an error occurs
  66.  
  67. if n_elements(rate) eq 0 then rate = 1.0 ;Parameter there?
  68. ichl = 0
  69. sfact = 1.5        ;Speed steps
  70.  
  71. if !d.name eq "SUN" then begin
  72.     if n_elements(r_orig) eq 0 then begin    ;colors defined?
  73.         r_orig=indgen(256) & g_orig = r_orig & b_orig = r_orig
  74.         endif
  75.  
  76.     p1 = 16 * [[ lindgen(256)/16], [ lindgen(256) and 15]] ;(256,2)
  77.  
  78.     device, set_write=240    ;load top 4 bits
  79.     tv,a
  80.     empty
  81.     device, set_write=15    ;load bottom 4 bits
  82.     tv,b/16b
  83.     empty
  84.     device,set_write=255    ;re-enable all 8 bits
  85.  
  86.     while 1 do begin    ;loop infinitely over each chl
  87.         p = p1[*,ichl]    ;get appropriate table
  88.         tvlct,r_orig[p], g_orig[p], b_orig[p] ;load 4 bit table
  89.         wait,1./rate    ;This also empties the graphics buffer
  90.         chr = get_kbrd(0) ;Read character
  91.         case strupcase(chr) of
  92.     "F":    rate = rate*sfact    ;Faster
  93.     "S":     rate = rate/sfact    ;Slower
  94.     "":    ichl = 1 - ichl    ;Other image
  95.     else:    goto,done
  96.         endcase
  97.     endwhile
  98. ;
  99.     done:    tvlct, r_orig, g_orig, b_orig
  100.     empty
  101.     return
  102.  
  103. ENDIF ELSE BEGIN            ;Assume X or Windows
  104.     if !d.window lt 0 then window
  105.     cwin = !d.window
  106.     pix = intarr(2)        ;Make 2 pixmaps
  107.     for i=0,1 do begin
  108.         window, /FREE, /PIX, xs = !d.x_size, ys = !d.y_size
  109.         pix[i] = !d.window
  110.         if i eq 0 then tv,a else tv,b
  111.         endfor
  112.     wset, cwin
  113.     while 1 do begin    ;loop infinitely over each chl
  114.         device, copy=[0,0,!d.x_size, !d.y_size, 0, 0, pix[ichl]]
  115.         wait,1./rate    ;This also empties the graphics buffer
  116.         chr = get_kbrd(0) ;Read character
  117.         case strupcase(chr) of
  118.     "F":    rate = rate*sfact    ;Faster
  119.     "S":     rate = rate/sfact    ;Slower
  120.     "":    ichl = 1 - ichl    ;Other image
  121.     else:    goto,done1
  122.         endcase
  123.     endwhile
  124. ;
  125. done1:    wdelete, pix[0], pix[1]
  126.     return
  127. ENDELSE
  128. end
  129.